const {src, dest, parallel, series, watch} = require("gulp")
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const htmlmin = require('gulp-htmlmin');
const rename = require('gulp-rename');
const { server } = require("../../../模块三/3-1/gulp/03.working_with_files/gulpfile");
const del = require('del')
const browserSync = require('browser-sync').create();

const dele = () => {
    return del(['2-6dist'])
}
const style = () => {
    return src('2-6src/css/*.css',{base:'2-6src'})
    .pipe(cleanCSS())
    .pipe(rename({extname:'.min.css'}))
    .pipe(dest('2-6dist'))
}

const script = () => {
    return src('2-6src/js/axios.js',{base:"2-6src"})
    .pipe(uglify())
    .pipe(rename({extname:".min.js"}))
    .pipe(dest('2-6dist'))
}

const html = () => {
    return src('2-6src/index.html',{base:"2-6src"})
    .pipe(htmlmin({
        collapseWhitespace: true, removeComments:true 
    })).
    pipe(dest('2-6dist/'))
}

const trans = () => {
    return src('2-6src/js/*.min.js',{base:"2-6src"})
    .pipe(dest('2-6dist'))
}

const sever = () => {
    browserSync.init({
        server: {
            baseDir: "./2-6dist"
        }
    })
}
const bulid = series(dele,parallel(style,script,html,trans))
exports.start = series(bulid,server)